package com.test.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.test.enity.Employee;
import com.test.service.IEmployeeService;
import com.test.service.impl.EmployeeServiceImpl;

@WebServlet("/UpdateEmployeeServlet")
public class UpdateEmployeeServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");

		int id = Integer.parseInt(request.getParameter("id"));
		String name = request.getParameter("name");
		String sex = request.getParameter("sex");
		int age = Integer.parseInt(request.getParameter("age"));
		String dpartment = request.getParameter("dapartment");
		String type = request.getParameter("type");
		int year = Integer.parseInt(request.getParameter("year"));
		Employee employee = new Employee(name, sex, age, dpartment, type, year);
		IEmployeeService employeeService = new EmployeeServiceImpl();
		boolean result = employeeService.updateEmployee(id, employee);
		if (result) {
		//	response.getWriter().println("修改成功！");
			response.sendRedirect("QueryAllEmployeeServlet");
		} else {
			response.getWriter().println("修改失败！");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
